// Andrew Davies

#if !defined( PHYSICS_ENGINE_H )
#define PHYSICS_ENGINE_H

#include "Physics/Engine/physicsEngineFwd.h"
#include "Physics/Shape/physicsShape.h"
#include "d3d9.h"
#include <fuz/container/fixed_list.hpp>

namespace Physics
{
	
#define PHYSICS_SHAPE_NULL_UID ( INT_MAX )

#define PHYSICS_MAX_SHAPES ( ( int )128 )

typedef fuz::fixed_list< ShapeClass, PHYSICS_MAX_SHAPES > EngineShapeListType;
	
class EngineClass
{
private:
	int m_nextUID;
	EngineShapeListType m_shapeList;

	int m_stepCount;

public:
	EngineClass();

	void create();
	void destroy();

	void step( float deltaTime );
	void draw( IDirect3DDevice9 & d3dDevice ) const;

	int createShape(
		D3DXVECTOR4VectorType const & vertexVector,
		D3DXVECTOR4 const & position,
		float orientation,
		D3DXVECTOR4 const & velocity,
		float angularVelocity,
		D3DXVECTOR4 const & force,
		float torque,
		bool infiniteMass );

	void destroyShape( int UID );

	ShapeClass const * shape( int UID ) const;
	ShapeClass * shape( int UID );
	
	bool anyShapesInCollision() const;

	int nextUID() const
	{
		return m_nextUID;
	}
		
	EngineShapeListType const & shapeList() const
	{
		return m_shapeList;
	}

	int stepCount() const
	{
		return m_stepCount;
	}
		
};

}

#endif